<?php
//mysql_connect('localhost', 'gogoalsh_stock', 'admin#stock_all') or exit("0");
//mysql_select_db('gogoalsh_stock') or exit("0");
mysql_connect('localhost', 'root', '123456') or exit("0");;
mysql_select_db('kucun') or exit("0");

if(!empty($_GET['sku'])){
	//通过sku请求的是获取库存
	$sql = 'select v.*, s.is_forlong from stock s inner join stock_value v on s.sku=v.sku where s.sku = "'.addslashes($_GET['sku']).'"'.'order by v.id asc';
	$result = mysql_query($sql);
	$arr = array();
	while ($row = mysql_fetch_array($result)) {
		$arr[] = $row;
	}
	if (empty($arr)) {
		echo 0;
	} else {
		echo json_encode($arr);
	}
}

if(!(empty($_GET['oid']) || empty($_GET['site']))){
	//获取订单信息
	$sql1 = 'select * from stock_log sl where sl.site = "'.addslashes($_GET['site']).'" and sl.order_id = "'.addslashes($_GET['oid']).'"'.'order by sl.id asc';
	$result1 = mysql_query($sql1);
	$arr1 = array();
	while ($row1 = mysql_fetch_array($result1)) {
		$arr1[] = $row1;
	}
	
	//获取分拣信息
	$sql2 = 'select * from order_sort_log osl where osl.site = "'.addslashes($_GET['site']).'" and osl.order_id = "'.addslashes($_GET['oid']).'"'.'order by osl.id asc';
	$result2 = mysql_query($sql2);
	$arr2 = array();
	while ($row2 = mysql_fetch_array($result2)) {
		$arr2[] = $row2;
	}
	
	//获取打包信息
	$sql3 = 'select * from stock_export_log sel where sel.site = "'.addslashes($_GET['site']).'" and sel.order_id = "'.addslashes($_GET['oid']).'"'.'order by sel.id asc';
	$result3 = mysql_query($sql3);
	$arr3 = array();
	while ($row3 = mysql_fetch_array($result3)) {
		$arr3[] = $row3;
	}
	if (empty($arr1)) {
		echo 0;
	} else {
		echo json_encode(array('stocklog'=>$arr1,'sortlog'=>$arr2,'packlog'=>$arr3));
	}
}